home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Sources / FWPartng.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  14.3 KB  |  496 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPartng.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWPARTNG_H
  13. #include "FWPartng.h"
  14. #endif
  15.  
  16. #ifndef FWUTIL_H
  17. #include "FWUtil.h"
  18. #endif
  19.  
  20. #ifndef FWPRSTNG_H
  21. #include "FWPrstng.h"
  22. #endif
  23.  
  24. #ifndef FWPRTITE_H
  25. #include "FWPrtIte.h"
  26. #endif
  27.  
  28. #ifndef FWSELECT_H
  29. #include "FWSelect.h"
  30. #endif
  31.  
  32. #ifndef FWITERS_H
  33. #include "FWIters.h"
  34. #endif
  35.  
  36. #ifndef FWFRMING_H
  37. #include "FWFrming.h"
  38. #endif
  39.  
  40. #ifndef FWPXYFRM_H
  41. #include "FWPxyFrm.h"
  42. #endif
  43.  
  44. #ifndef FWLNKMGR_H
  45. #include "FWLnkMgr.h"
  46. #endif
  47.  
  48. #ifndef FWCMD_H
  49. #include "FWCmd.h"
  50. #endif
  51.  
  52. #ifndef FWPROXY_H
  53. #include "FWProxy.h"
  54. #endif
  55.  
  56. #ifndef FWPRMISE_H
  57. #include "FWPrmise.h"
  58. #endif
  59.  
  60. #ifndef FWITEXT_H
  61. #include "FWIText.h"
  62. #endif
  63.  
  64. #ifndef FWMNUBAR_H
  65. #include "FWMnuBar.h"
  66. #endif
  67.  
  68. #ifndef FWACQUIR_H
  69. #include "FWAcquir.h"
  70. #endif
  71.  
  72. #ifndef FWCLNINF_H
  73. #include "FWClnInf.h"
  74. #endif
  75.  
  76. // ----- OpenDoc Utilites -----
  77.  
  78. #ifndef _INFOUTIL_
  79. #include "InfoUtil.h"
  80. #endif
  81.  
  82. // ----- OpenDoc Includes -----
  83.  
  84. #ifndef SOM_Module_OpenDoc_Commands_defined
  85. #include <CmdDefs.xh>
  86. #endif
  87.  
  88. #ifndef SOM_ODSession_xh
  89. #include <ODSessn.xh>
  90. #endif
  91.  
  92. #ifndef SOM_ODStorageUnitView_xh
  93. #include <SUView.xh>
  94. #endif
  95.  
  96. #ifndef SOM_Module_OpenDoc_Foci_defined
  97. #include <Foci.xh>
  98. #endif
  99.  
  100. #ifndef SOM_Module_OpenDoc_StdProps_defined
  101. #include <StdProps.xh>
  102. #endif
  103.  
  104. #ifndef SOM_ODDraft_xh
  105. #include <Draft.xh>
  106. #endif
  107.  
  108. #ifndef SOM_ODClipboard_xh
  109. #include <Clipbd.xh>
  110. #endif
  111.  
  112. #ifndef SOM_ODArbitrator_xh
  113. #include <Arbitrat.xh>
  114. #endif
  115.  
  116. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  117. #include <StdTypes.xh>
  118. #endif
  119.  
  120. #ifdef FW_BUILD_WIN
  121.  
  122. #include <plfmdef.h>
  123. #include <t_regist.h>
  124.  
  125. #endif
  126.  
  127. //========================================================================================
  128. // RunTime Info
  129. //========================================================================================
  130.  
  131. #if FW_LIB_EXPORT_PRAGMAS
  132. #pragma lib_export on
  133. #endif
  134.  
  135. #ifdef FW_BUILD_MAC
  136. #pragma segment fw_embedding
  137. #endif
  138.  
  139. FW_DEFINE_CLASS_M1(FW_CEmbeddingPart, FW_CPart)
  140.  
  141. //========================================================================================
  142. //    class FW_CEmbeddingPart
  143. //========================================================================================
  144.  
  145. //----------------------------------------------------------------------------------------
  146. //    FW_CEmbeddingPart::FW_CEmbeddingPart    
  147. //----------------------------------------------------------------------------------------
  148.  
  149. FW_CEmbeddingPart::FW_CEmbeddingPart(ODPart* odPart, 
  150.                                     ODValueType partKind, 
  151.                                     ODValueType partUserName,
  152.                                     FW_Instance partInstance, 
  153.                                     FW_ResourceId iconID) :
  154.     FW_CPart(odPart, partKind, partUserName, partInstance, iconID),
  155.     fProxyFrames(NULL)
  156. #ifdef FW_BUILD_WIN
  157.     ,fWinEmbedMenu(NULL)
  158. #endif
  159. {
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------
  163. //    FW_CEmbeddingPart::~FW_CEmbeddingPart    
  164. //----------------------------------------------------------------------------------------
  165.  
  166. FW_CEmbeddingPart::~FW_CEmbeddingPart()
  167. {    
  168.     delete fProxyFrames;
  169.     fProxyFrames = NULL;
  170. }
  171.  
  172. //---------------------------------------------------------------------------------------
  173. //    FW_CEmbeddingPart::Initialize
  174. //---------------------------------------------------------------------------------------
  175. // Call inherited first when overriding
  176.  
  177. void FW_CEmbeddingPart::Initialize(Environment *ev)
  178. {
  179.     FW_CPart::Initialize(ev);
  180.     
  181.     // ----- Proxy Frame collection -----
  182.     fProxyFrames = new FW_CPrivOrderedCollection;
  183. }
  184.  
  185. //---------------------------------------------------------------------------------------
  186. //    FW_CEmbeddingPart::LinkStatusChanged
  187. //---------------------------------------------------------------------------------------
  188.  
  189. void FW_CEmbeddingPart::LinkStatusChanged(Environment *ev, ODFrame* odFrame)
  190. {
  191.     // The following code is default behavior for parts that don't create links.
  192.  
  193.     FW_CEmbeddingFrame* frame = FW_CEmbeddingFrame::ODtoFWEmbeddingFrame(ev, odFrame);
  194.     if (frame)
  195.     {
  196.         ODLinkStatus linkStatus = odFrame->GetLinkStatus(ev);
  197.  
  198.         // You only need to propagate linkStatus to embedded frames that don't participate in
  199.         // any of this part's links; otherwise their local link status takes precedence.
  200.  
  201.         FW_CPartEmbeddedFrameIterator iter(ev, this);
  202.         for (ODFrame* odEmbeddedFrame = iter.First(ev); iter.IsNotComplete(ev); odEmbeddedFrame = iter.Next(ev))
  203.             odEmbeddedFrame->ChangeLinkStatus(ev, linkStatus);
  204.     }
  205. }
  206.  
  207. //----------------------------------------------------------------------------------------
  208. //    FW_CEmbeddingPart::ReleaseAll
  209. //----------------------------------------------------------------------------------------
  210. //    Call inherited first when overrided
  211.  
  212. void FW_CEmbeddingPart::ReleaseAll(Environment *ev)
  213. {
  214.     FW_CPart::ReleaseAll(ev);
  215.  
  216.     // ----- Delete Proxy Frames collection -----
  217.     if (fProxyFrames)
  218.     {
  219.         FW_CProxyFrame* proxyFrame;
  220.         while ((proxyFrame = (FW_CProxyFrame*)fProxyFrames->First()) != NULL)
  221.         {
  222.             PrivRemoveProxyFrame(ev, proxyFrame);
  223.         }
  224.     }
  225. }
  226.  
  227. //---------------------------------------------------------------------------------------
  228. //    FW_CEmbeddingPart::Purge
  229. //---------------------------------------------------------------------------------------
  230.  
  231. ODSize FW_CEmbeddingPart::Purge(Environment *ev, ODSize size)
  232. {
  233.     ODSize odSize = FW_CPart::Purge(ev, size);
  234.     
  235.     // ----- Purge embedded frames -----
  236.     if (IsSupportingFramePaging(ev))
  237.     {    
  238.         FW_CPartProxyFrameIterator ite(this);
  239.         for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
  240.         {
  241.             odSize += proxyFrame->Purge(ev);
  242.         }
  243.     }
  244.     
  245.     return odSize;
  246. }
  247.  
  248. //---------------------------------------------------------------------------------------
  249. //    FW_CEmbeddingPart::Dragging
  250. //---------------------------------------------------------------------------------------
  251.  
  252. void FW_CEmbeddingPart::Dragging(Environment *ev, FW_CFrame* frame, FW_Boolean state)
  253. {
  254.     FW_CPartProxyFrameIterator ite(this);
  255.     for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
  256.     {
  257.         if (proxyFrame->IsFrameInMemory(ev) && proxyFrame->GetContainingFrame(ev) == frame)
  258.         {
  259.             if (proxyFrame->HasASelectedFacet(ev))
  260.                 proxyFrame->GetFrame(ev)->SetDragging(ev, state);
  261.         }
  262.     }
  263. }
  264.  
  265. //---------------------------------------------------------------------------------------
  266. //    FW_CEmbeddingPart::GetProxy
  267. //---------------------------------------------------------------------------------------
  268.  
  269. FW_MProxy* FW_CEmbeddingPart::GetProxy(Environment* ev, ODFrame* embeddedFrame) const
  270. {
  271.     FW_ASSERT(embeddedFrame != NULL);
  272.     
  273.     ODID embeddedFrameID = embeddedFrame->GetID(ev);
  274.     
  275.     FW_CPartProxyFrameIterator ite(this);
  276.     for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
  277.     {
  278.         if (proxyFrame->GetFrameID(ev) == embeddedFrameID)
  279.             return proxyFrame->GetProxy(ev);
  280.     }
  281.     
  282.     return NULL;
  283. }
  284.  
  285. //---------------------------------------------------------------------------------------
  286. //    FW_CEmbeddingPart::PrivAddProxyFrame
  287. //---------------------------------------------------------------------------------------
  288.  
  289. void FW_CEmbeddingPart::PrivAddProxyFrame(Environment* ev, FW_CProxyFrame* proxyFrame)
  290. {
  291.     fProxyFrames->AddLast(proxyFrame);
  292.     proxyFrame->Acquire();
  293. }
  294.  
  295. //---------------------------------------------------------------------------------------
  296. //    FW_CEmbeddingPart::PrivRemoveProxyFrame
  297. //---------------------------------------------------------------------------------------
  298.  
  299. long FW_CEmbeddingPart::PrivRemoveProxyFrame(Environment* ev, FW_CProxyFrame* proxyFrame)
  300. {
  301.     fProxyFrames->Remove(proxyFrame);
  302.     return proxyFrame->Release();
  303. }
  304.  
  305. //----------------------------------------------------------------------------------------
  306. //    FW_CEmbeddingPart::PrivAcquireProxyFrame
  307. //----------------------------------------------------------------------------------------
  308.  
  309. FW_CProxyFrame* FW_CEmbeddingPart::PrivAcquireProxyFrame(Environment* ev, ODStorageUnitID frameID) const
  310. {
  311.     return FW_CProxyFrame::PrivAcquireProxyFrame(ev, fProxyFrames, frameID);
  312. }
  313.  
  314. //---------------------------------------------------------------------------------------
  315. //    FW_CEmbeddingPart::CloneInto
  316. //---------------------------------------------------------------------------------------
  317.  
  318. void FW_CEmbeddingPart::PrivCloneInto(Environment *ev,
  319.                                     ODDraftKey key,
  320.                                     ODStorageUnit* toSU,
  321.                                     ODFrame* scope)
  322. {
  323.     ODStorageUnit* su = GetStorageUnit(ev);
  324.     ODDraft* fromDraft = su->GetDraft(ev);
  325.  
  326.     FW_ASSERT((scope == NULL) || (scope != NULL && IsValidDisplayFrame(ev, scope->GetID(ev))));
  327.  
  328.     FW_CFrame *frame = scope == NULL ? NULL : FW_CFrame::ODtoFWFrame(ev, scope);
  329.     FW_ASSERT((scope == NULL) || (scope != NULL && frame != NULL));
  330.     
  331.     FW_CCloneInfo cloneInfo(ev, key, fromDraft, frame, 0);        // fromDraft->GetCloneKind(ev)
  332.  
  333.     // ----- clone the proxy frames -----
  334.     PrivExternalizeProxyFrames(ev, toSU, &cloneInfo);
  335.     
  336.     // ----- Externalize the content -----
  337.     ExternalizeContent(ev, toSU, &cloneInfo);
  338. }
  339.  
  340. //---------------------------------------------------------------------------------------
  341. //    FW_CEmbeddingPart::PrivInternalizeProxyFrames
  342. //---------------------------------------------------------------------------------------
  343.  
  344. void FW_CEmbeddingPart::PrivInternalizeProxyFrames(Environment *ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
  345. {    
  346.     if (!FW_SUExistsThenFocus(ev, storageUnit, FW_kPropEmbeddedFrames, kODStrongStorageUnitRefs))
  347.         return;
  348.     
  349.     FW_CAcquireODStorageUnitView suView(ev, storageUnit);
  350.  
  351.     unsigned long offsetLimit = suView->GetSize(ev);
  352.  
  353.     while (suView->GetOffset(ev) < offsetLimit)
  354.     {            
  355.         FW_CAcquiredProxyFrame aqProxyFrame = new FW_CProxyFrame(ev, this);
  356.     
  357.         if (!aqProxyFrame->InternalizeProxyFrame(ev, suView, cloneInfo))
  358.         {
  359.             long refCount = this->PrivRemoveProxyFrame(ev, aqProxyFrame);    // should delete the proxy
  360.             FW_ASSERT(refCount == 0);
  361.         }
  362.     }
  363. }
  364.  
  365. //---------------------------------------------------------------------------------------
  366. //    FW_CEmbeddingPart::PrivExternalizeProxyFrames
  367. //---------------------------------------------------------------------------------------
  368.  
  369. void FW_CEmbeddingPart::PrivExternalizeProxyFrames(Environment *ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
  370. {
  371.     if (fProxyFrames->Count() == 0)
  372.     {
  373.         FW_SURemoveProperty(ev, storageUnit, FW_kPropEmbeddedFrames);    // FW_SURemoveProperty test first that the property exist
  374.         return;
  375.     }
  376.         
  377.     // ----- force the creation of the FW_kPropEmbeddedFrames property
  378.     FW_SUForceFocus(ev, storageUnit, FW_kPropEmbeddedFrames, kODStrongStorageUnitRefs);
  379.         
  380.     // ----- Create a storage unit view -----
  381.     FW_CAcquireODStorageUnitView suView(ev, storageUnit);
  382.  
  383.     // ----- Save previous value -----
  384.     unsigned long oldValueSize = suView->GetSize(ev);
  385.     
  386.     // ----- Set offset to zero -----
  387.     suView->SetOffset(ev, 0);
  388.     
  389.     // ----- Externalize Each proxy frame -----
  390.     FW_COrderedCollectionIterator ite(fProxyFrames);
  391.     for (FW_CProxyFrame* proxyFrame = (FW_CProxyFrame*)ite.First(); ite.IsNotComplete(); proxyFrame = (FW_CProxyFrame*)ite.Next())
  392.     {
  393.         proxyFrame->ExternalizeProxyFrame(ev, suView, cloneInfo);
  394.     }
  395.     
  396.     // ----- Get the current position -----
  397.     unsigned long offset = suView->GetOffset(ev);
  398.     
  399.     // ----- remove what's left -----
  400.     if (oldValueSize > offset)
  401.         suView->DeleteValue(ev, oldValueSize - offset);
  402.  
  403.     FW_ASSERT(suView->GetSize(ev) == offset);
  404. }
  405.  
  406. //----------------------------------------------------------------------------------------
  407. //    FW_CEmbeddingPart::NewPresentation    
  408. //----------------------------------------------------------------------------------------
  409.  
  410. FW_CPresentation* FW_CEmbeddingPart::NewPresentation(Environment *ev, 
  411.                                                     FW_CSelection* selection,
  412.                                                     ODTypeToken presentationType)
  413. {
  414.     return new FW_CEmbeddingPresentation(ev, this, (FW_CEmbeddingSelection*)selection, presentationType);
  415. }
  416.  
  417. #ifdef FW_BUILD_WIN
  418. //------------------------------------------------------------------------------
  419. //    FW_CEmbeddingPart::WinAddEmbedMenu
  420. //------------------------------------------------------------------------------
  421.  
  422. void FW_CEmbeddingPart::WinAddEmbedMenu(Environment *ev, FW_CMenuBar *menuBar)
  423. {
  424.     ODPartRegistryIterator    iter;
  425.     ODPartRegistryData        data;
  426.     char                     partString[50];
  427.     LPSTR                    partPtr, tmpPtr;
  428.  
  429.     unsigned short partCount = -1;     //TAG - this will increment the 1st time to 0 to
  430.                                     //        exclude the omnipresent IDM_DRAW part...
  431.                                     
  432.     unsigned short stringIndex = 0;    //    This indexes into part type string buffer.
  433.     fWinFirstPartID = FW_kFirstUserCommandID + 0x8000;
  434.     
  435.     fWinEmbedMenu = new FW_CPullDownMenu(ev, FW_CString32("Embed"));
  436.  
  437.     for (iter.First(kODTrue,&data);iter.IsNotComplete();iter.Next(&data)) 
  438.     {
  439.         partCount++;
  440.  
  441.         //    Keep the last word of the partKind
  442.         FW_PrimitiveStringCopy(data.partKind, partPtr=partString);
  443.         tmpPtr = partPtr;
  444.         while (tmpPtr != NULL)
  445.         {
  446.             tmpPtr = FW_PrimitiveStringFindCharacter(partPtr, ':');
  447.             if (tmpPtr != NULL)
  448.                 partPtr = ++tmpPtr;
  449.         }
  450.         
  451.         FW_CString255 name(partPtr);
  452.         fWinEmbedMenu->AppendTextItem(ev, name, fWinFirstPartID + partCount);
  453.         
  454.         fTypePtr[partCount] = &(fTypeString[stringIndex]);
  455.         FW_PrimitiveStringCopy(data.partKind, fTypePtr[partCount]);
  456.         stringIndex += FW_PrimitiveStringLength(fTypePtr[partCount]) + 1;
  457.     }
  458.     fWinLastPartID = fWinFirstPartID + partCount;
  459.  
  460.     menuBar->AdoptMenuLast(ev, fWinEmbedMenu);
  461. }
  462. #endif
  463.  
  464. #ifdef FW_BUILD_WIN
  465. //----------------------------------------------------------------------------------------
  466. //    FW_CEmbeddingPart::WinCreateEmbeddedPartFromCommand
  467. //----------------------------------------------------------------------------------------
  468.  
  469. ODPart* FW_CEmbeddingPart::WinCreateEmbeddedPartFromCommand(Environment* ev, ODCommandID commandID)
  470. {
  471.     if ((commandID >= fWinFirstPartID) && (commandID <= fWinLastPartID))
  472.     {
  473.         ODStorageUnit* su = this->GetStorageUnit(ev);
  474.         return su->GetDraft(ev)->CreatePart(ev, fTypePtr[commandID - fWinFirstPartID], NULL);
  475.     }
  476.     
  477.     return NULL;
  478. }
  479. #endif
  480.  
  481. #ifdef FW_BUILD_WIN
  482. //----------------------------------------------------------------------------------------
  483. //    FW_CEmbeddingPart::WinEnableEmbedMenu
  484. //----------------------------------------------------------------------------------------
  485.  
  486. void FW_CEmbeddingPart::WinEnableEmbedMenu(Environment* ev, FW_CMenuBar* menuBar)
  487. {
  488.     if (fWinEmbedMenu != NULL && fWinEmbedMenu->GetMenuBar(ev) == menuBar)
  489.     {
  490.         fWinEmbedMenu->EnableAll(ev);
  491.     }
  492. }
  493. #endif
  494.  
  495.  
  496.